'Animals TR Submission
Option Strict Off
imports System
imports PHSRAG.Insight21.Humans
imports PHSRAG.Insight21.BusinessObjects
imports FormsManagement = PHSRAG.Insight21.FormsManagement
imports System.Collections
imports CDS = PHSRAG.Insight21.CDS

module Script
    sub Main()
    
        Dim qV As FormsManagement.QuestionnaireVersion
        Dim questionnaireAnswer As FormsManagement.QuestionnaireAnswer

        For Each questionnaireAnswer In currentProtVersion.QuestionnaireAnswers
                
            qV  = questionnaireAnswer.QuestionnaireVersion
            Dim answers as new ArrayList()
            
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '  Triennial Review
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
            
            ' Note: Default the status to "Active" per Robin, since Triennial Reviews
            ' require a status in Rex, but there's no question for this.
            rexParams.ProjectStatus = "Active"
           
            If (qV.Questionnaire.Name = "Triennial Review") Then
                
                    
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '  Hazardous Agent Administration and Use
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''          
            else If qV.Questionnaire.Name = "Hazardous Agent Administration and Use"
                answers = nothing
                answers = questionnaireAnswer.GetAnswers("HazardType")
                if ( answers.Count > 0) then
                    Dim newComponent as RexParams.ComponentToChange = new RexParams.ComponentToChange
                    rexParams.ComponentsToChange.Add ( newComponent )

                    Dim singleAnswer as FormsManagement.Answer = answers(0)
                    Select Case singleAnswer.Value
                        Case "Bio"
                            newComponent.Component = "Biological Agents"
                        Case "Chem"
                            newComponent.Component = "Toxic Chemicals/Carcinogens"
                        Case "Rad"
                            newComponent.Component = "Radioisotopes"
                    End Select
                end if
          
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '  STANDARD APPLICATION
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
            else If (qV.Questionnaire.Name = "Standard Application") 
                    'Dim answers as new ArrayList()
                    answers = questionnaireAnswer.GetAnswers("LabHousing") 
                        If (answers.Count > 0) Then
                            Dim housing as FormsManagement.Answer = answers(0)
                            if housing.Value = "Y" then
                                rexParams.HousingOver12 = true
                            else	
                                rexParams.HousingOver12 = false
                            end if
                        End If

                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("SpecialHandling")
                        If (answers.Count > 0) Then
                                Dim husbImmune as FormsManagement.Answer = answers(0)
                            if husbImmune.Value = "Breeding" then
                                rexParams.specialHandling.Add("Breeding")
                            end if
                        End If

                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("HusbandGenetic")
                    If (answers.Count > 0) Then
                             Dim husbandGenetic as FormsManagement.Answer = answers(0)
                        if husbandGenetic.Value = "GENETIC" then
                            rexParams.specialHandling.Add("Transgenic")
                        end if
                    End If
                
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("HusbImmune")
                    If (answers.Count > 0) Then
                            Dim husbImmune as FormsManagement.Answer = answers(0)
                        if husbImmune.Value = "IMMUNE" then
                            rexParams.specialHandling.Add("ImmunoSuppresed")
                        end if
                    End If

        
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("Resubmission")
                    If (answers.Count > 0) Then
                            Dim resub as FormsManagement.Answer = answers(0)
                        if resub.Value = "Y" then
                            rexParams.Resubmission = true
                        else	
                            rexParams.Resubmission = false
                        end if
                    End If
                
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("PreviousProtocol")
                    If (answers.Count > 0) Then
                        Dim prevProt as FormsManagement.Answer = answers(0)
                        Dim val as string = prevProt.Value
                        rexParams.PreviousFolderNumber = Left(val, 13)
                    End If
                
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("Housing")
                    AddHousing(answers, "STD_APP", questionnaireAnswer)
                            
                    Dim labLocation as AnimalsRexParams.LabLocation
                    answers = nothing					
                                answers = questionnaireAnswer.GetAnswers("LabLoc") 
                                Dim buildingAnswer As FormsManagement.Answer					   
                                    If (answers.Count > 0) Then
                                        For Each buildingAnswer In answers
                                            if buildingAnswer.Value <> nothing and buildingAnswer.Value <> string.Empty then
                                                    labLocation = new AnimalsRexParams.LabLocation				                        			                    				    
                                                    labLocation.BuildingCode =  buildingAnswer.Value				                             
                                                    if buildingAnswer.Value = "CNY114" then        				                       
                                                            rexParams.LabLocations.Add (labLocation)	
                                                            Dim roomAnswers as new ArrayList()
                                                            roomAnswers = questionnaireAnswer.GetAnswers("Lab114")
                                                            If ( roomAnswers.Count > 0) Then
                                                                Dim room as FormsManagement.Answer = roomAnswers(0)
                                                                labLocation.RoomNumber = room.Value				                                        
                                                            End If 
                                                    else if buildingAnswer.Value = "CNY149" then
                                                            rexParams.LabLocations.Add (labLocation)	
                                                            Dim roomAnswers as new ArrayList()
                                                            roomAnswers = questionnaireAnswer.GetAnswers("Lab149")
                                                            If ( roomAnswers.Count > 0) Then
                                                                Dim room as FormsManagement.Answer = roomAnswers(0)
                                                                labLocation.RoomNumber = room.Value				                                        
                                                            End If
                                                    else if buildingAnswer.Value = "CNY75" then
                                                            labLocation.BuildingCode = "75"
                                                            rexParams.LabLocations.Add (labLocation)	
                                                            Dim roomAnswers as new ArrayList()
                                                            roomAnswers = questionnaireAnswer.GetAnswers("Lab75")
                                                            If ( roomAnswers.Count > 0) Then
                                                                Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "BAR" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabBAR")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "BHX" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabBHX")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "BLK" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabBLK")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "BUL" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabBUL")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "COX" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabCox")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "CPZ" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabCPZ")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "EDR" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabEDR")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "ELL" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabELL")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "FND" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabFND")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "GRB" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabGRB")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "GRJ" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabGRJ")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "SHR" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabSHR")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "THR" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabTHR")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "VBK" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabVBK")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "WHT" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabWHT")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                else if buildingAnswer.Value = "WRN" then
                                                        rexParams.LabLocations.Add (labLocation)	
                                                        Dim roomAnswers as new ArrayList()
                                                        roomAnswers = questionnaireAnswer.GetAnswers("LabWRN")
                                                        If ( roomAnswers.Count > 0) Then
                                                            Dim room as FormsManagement.Answer = roomAnswers(0)
                                                            labLocation.RoomNumber = room.Value				                                        
                                                        End If
                                                end if				                            
                                       end if
                                    Next           					
                            End If
                
                            AddArrayListItem( questionnaireAnswer, "Ascites", "ASCITES", rexParams.Considerations, "Ascites production" )
                            AddArrayListItem( questionnaireAnswer, "Tumor", "TUMOR", rexParams.Considerations, "Tumor growth" )
                            AddArrayListItem( questionnaireAnswer, "LD50", "LD50", rexParams.Considerations, "Death as an endpoint (i.e. LD50)" )
                            AddArrayListItem( questionnaireAnswer, "Burns", "BURNS", rexParams.Considerations, "Burns or trauma" )
                            AddArrayListItem( questionnaireAnswer, "Device", "DEVICE", rexParams.Considerations, "Device evaluation" )
                            AddArrayListItem( questionnaireAnswer, "Tran", "TRAN", rexParams.Considerations, "Transportation between non-MGH facilities" )
                            AddArrayListItem( questionnaireAnswer, "IntraTran", "INTRATRAN", rexParams.Considerations, "Transportation between MGH facilities" )
                            AddArrayListItem( questionnaireAnswer, "OffSiteHousing", "NONMGH", rexParams.Considerations, "Housing at non-MGH facilities" )
                            AddArrayListItem( questionnaireAnswer, "Surgery", "Sx", rexParams.Considerations, "Survival Surgery" )
                            AddArrayListItem( questionnaireAnswer, "SxProcedures", "MxSx", rexParams.Considerations, "Multiple survival operative procedures" )
                            AddArrayListItem( questionnaireAnswer, "Paralytic", "PARALYTICS", rexParams.Considerations, "Paralytic agents" )
                            AddArrayListItem( questionnaireAnswer, "Fluid", "FLUID", rexParams.Considerations, "Food or water deprivation" )
                            AddArrayListItem( questionnaireAnswer, "PainStudy", "PAIN", rexParams.Considerations, "Study of pain or stress" )
                            AddArrayListItem( questionnaireAnswer, "UnPain", "UNPAIN", rexParams.Considerations, "Unalleviated pain or distress" )
                
                            ''' CatBNum
                            answers = nothing
                            answers = questionnaireAnswer.GetAnswers("CatBNum")
                            If (answers.Count > 0) Then
                                Dim catBNum as FormsManagement.Answer = answers(0)
                                Dim i as integer = 0
                                if IsNumeric ( catBNum.Value ) then
                                    i = FormatNumber(catBNum.Value)
                                end if
                                rexParams.CatBNum = i
                            End If
                            
                            ''' CatCNum
                            answers = nothing
                            answers = questionnaireAnswer.GetAnswers("CatCNum")
                            If (answers.Count > 0) Then
                                Dim catCNum as FormsManagement.Answer = answers(0)
                                Dim i as integer = 0
                                if IsNumeric ( catCNum.Value ) then
                                    i = FormatNumber(catCNum.Value)
                                end if
                                rexParams.CatCNum = i
                            End If
                            
                            ''' CatDNum
                            answers = nothing
                            answers = questionnaireAnswer.GetAnswers("CatDNum")
                            If (answers.Count > 0) Then
                                Dim catDNum as FormsManagement.Answer = answers(0)
                                Dim i as integer = 0
                                if IsNumeric ( catDNum.Value ) then
                                    i = FormatNumber(catDNum.Value)
                                end if
                                rexParams.CatDNum = i
                            End If
                            
                            ''' CatENum
                            answers = nothing
                            answers = questionnaireAnswer.GetAnswers("CatENum")
                            If (answers.Count > 0) Then
                                Dim catENum as FormsManagement.Answer = answers(0)
                                Dim i as integer = 0
                                if IsNumeric ( catENum.Value ) then
                                    i = FormatNumber(catENum.Value)
                                end if
                                rexParams.CatENum = i
                            End If
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '' Tumor Production
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''	  
            Else If (qV.Questionnaire.Name = "Tumor Production") Then
          
                Dim refCodes as CDS.RefCodes = new CDS.RefCodes(cachePolicy)
                refCodes.Load(connectionString, Nothing)

		        Dim newTumorLine as AnimalsRexParams.TumorCellLine = new AnimalsRexParams.TumorCellLine
				rexParams.TumorCellLines.Add (newTumorLine)
					
                newTumorLine.TumorCellLineName = questionnaireAnswer.GetAnswerValue("Tumor") 
				
				Dim rodOrigin as string = questionnaireAnswer.GetAnswerValue("RodentOrigin") 
				if rodOrigin = "Y" then
	                newTumorLine.RodentOrigin = refCodes.GetRefCode("ANIMCELLRODSOURCE", questionnaireAnswer.GetAnswerValue("RodSource")).Meaning
	                if newTumorLine.RodentOrigin = "Other" then
	                    newTumorLine.OriginOther = questionnaireAnswer.GetAnswerValue("OtrSpecies")
	                end if
				else
	                newTumorLine.RodentOrigin = refCodes.GetRefCode("ANIMCELLNONRODSOURCE", questionnaireAnswer.GetAnswerValue("NonRodSource")).Meaning
	                if newTumorLine.RodentOrigin = "Other" then
	                    newTumorLine.OriginOther = questionnaireAnswer.GetAnswerValue("NonOtrSpecies")
	                end if
				end if

				Dim answerValue as string
				answerValue = questionnaireAnswer.GetAnswerValue("PassRod") 
				If answerValue = "Y" Then
                    newTumorLine.passRodent = true
                Else
                    newTumorLine.passRodent = false
                End If

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '' Detailed Research Plan
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Else If (qV.Questionnaire.Name = "Detailed Research Plan") Then
        
                    'Dim answers as new ArrayList()
                    answers = questionnaireAnswer.GetAnswers("Breeding") 
                    If (answers.Count > 0) Then
                        Dim passRod as FormsManagement.Answer = answers(0)
                        If passRod.Value = "Yes" Then
                            rexParams.Considerations.Add ( "Breeding Colony" )
                        End If
                    End If
            
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("Conscious") 
                    If (answers.Count > 0) Then
                        Dim conscious as FormsManagement.Answer = answers(0)
                        If conscious.Value = "CON" then
                            ' if CON and PROLONGED, then set another Special Consideration
                            Dim prolongeds  as new ArrayList()
                            prolongeds = questionnaireAnswer.GetAnswers("Duration") 
                            if ( prolongeds.Count > 0 ) then
                                Dim prolonged as FormsManagement.Answer = prolongeds(0)
                                If prolonged.Value = "PROLONGED" Then
                                    rexParams.Considerations.Add ( "Prolonged restraint" )
                                End If
                            end if
                        end If
                    End If
                
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("ResType") 
                    If (answers.Count > 0) Then
                        Dim conscious as FormsManagement.Answer = answers(0)
                        If conscious.Value = "OTHER" then
                            rexParams.Considerations.Add ( "Unconventional restraint or behavior" )
                        end If
                    End If
            
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '' Procedures
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Else If (qV.Questionnaire.Name = "Procedures") Then
            
                    Dim refCodes as CDS.RefCodes = new CDS.RefCodes(cachePolicy)
                    refCodes.Load(connectionString, Nothing)

                    Dim newProcedure as AnimalsRexParams.Procedure = new AnimalsRexParams.Procedure
                    rexParams.Procedures.Add (newProcedure)
                    
                    'Dim answers as new ArrayList()
                    answers = questionnaireAnswer.GetAnswers("ProcName")
                    
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("Surgical")
                    If ( answers.Count > 0) Then
                        Dim surgType as FormsManagement.Answer = answers(0)
                        If surgType.Value = "Surgical" Then
                            newProcedure.SurgicalType = surgType.Value
                            Dim surgicalAnswers as ArrayList = questionnaireAnswer.GetAnswers("SurgName")
                            if surgicalAnswers.Count > 0 then
                                newProcedure.SurgName = refCodes.GetRefCode("ANIMPROCEDURE", surgicalAnswers(0).Value).Meaning
                            end if
                        Else If surgType.Value = "Non" Then
                            newProcedure.SurgicalType = "Non-Surgical"
                            Dim procedureAnswers as ArrayList = questionnaireAnswer.GetAnswers("ProcName")
                            if procedureAnswers.Count > 0 then
                               newProcedure.SurgName = refCodes.GetRefCode("ANIMPROCEDURE", procedureAnswers(0).Value).Meaning
                            end if
                        End If
                        
                    End If 
                
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("Survival")
                    If ( answers.Count > 0) Then
                        Dim survival as FormsManagement.Answer = answers(0)
                        If survival.Value = "Survival" Then
                            newProcedure.Survival = survival.Value
                        Else If survival.Value = "Non" Then
                            newProcedure.Survival = "Non-Survival"
                        End If    				   
                    End If 
                    
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("Build")
                    If ( answers.Count > 0) Then
                        Dim procBuilding as FormsManagement.Answer = answers(0)
                        If not procBuilding.Value is nothing or procBuilding.Value <> string.empty Then
                           newProcedure.Building = procBuilding.Value
                        End If    				   
                    End If 	
                    
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("Room")
                    If ( answers.Count > 0) Then
                        Dim procRoom as FormsManagement.Answer = answers(0)
                        If not procRoom.Value is nothing or procRoom.Value <> string.empty Then
                           newProcedure.Room = procRoom.Value
                        End If    				   
                    End If 

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '' Tissues
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Else If (qV.Questionnaire.Name = "Tissue") Then
            
                    Dim newTissue as AnimalsRexParams.Tissue = new AnimalsRexParams.Tissue
                    rexParams.Tissues.Add (newTissue)
                    
                    'Dim answers as ArrayList
                    answers = questionnaireAnswer.GetAnswers("Type")
                    If ( answers.Count > 0) Then
                        Dim tissueType as string = answers(0).value

                        For each questionnaireItem as FormsManagement.QuestionnaireItem in qv.Items
                            if ( questionnaireItem.Name = "Type") then
                                for each itemOption as FormsManagement.ItemOption in  questionnaireItem.Options
                                    if (itemOption.OptionValue = tissueType) then
                                        newTissue.Type = itemOption.OptionText
                                        exit for
                                    end if
                                next
                                exit for
                            end if
                        Next
                    End If 
                
                    answers = questionnaireAnswer.GetAnswers("Source")
                    If ( answers.Count > 0) Then
                        'If "INT" is selected in question name "Source", then "Protocol" is selected in source column in Rex and the answers given to insight question "ProtNum" populates "Protocol/Vendor Name".  
                        newTissue.Source = "Protocol"
                        answers = questionnaireAnswer.GetAnswers("ProtNum")
                        if (answers.Count > 0) Then
                            newTissue.VendorName = answers(0).Value
                        End If
                    End If 
                
                    answers = questionnaireAnswer.GetAnswers("ColSource")
                    If ( answers.Count > 0) Then
                        'If "COL" is checked in insight question name "ColSource", then "Protocol" is selected in source column in Rex.  The answer given to insight "ColInfo" populates "Protocol Contact" in Rex.
                        newTissue.Source = "Protocol"
                        answers = questionnaireAnswer.GetAnswers("ColInfo")
                        if (answers.Count > 0) Then
                            newTissue.ProtocolContact = answers(0).Value
                        End If
                    End If	
                
                    answers = questionnaireAnswer.GetAnswers("BSHSource")
                    If ( answers.Count > 0) Then
                        'If "BSH" is checked in insight question name "BSHSource, then "Vendor" is selected in source column in Rex.  The answer given to insight "Company" populates "Protocol/Vendor Name" in Rex.
                        newTissue.Source = "Vendor"
                        answers = questionnaireAnswer.GetAnswers("Company")
                        if (answers.Count > 0) Then
                            newTissue.VendorName = answers(0).Value
                        End If
                    End If
                
                    answers = questionnaireAnswer.GetAnswers("OTRSource")
                    If ( answers.Count > 0) Then
                        'If "OTR" is checked in insight question name "OtrSource" then "Vendor" is selected in source column in Rex.  The answer given to insight "Other" populates "Protocol Contact" in Rex.
                        newTissue.Source = "Vendor"
                        answers = questionnaireAnswer.GetAnswers("Other")
                        if (answers.Count > 0) Then
                            newTissue.ProtocolContact = answers(0).Value
                        End If
                    End If	
                
                
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '' Abstract  TODO: Add in the questions here...
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Else If ( qV.Questionnaire.Name = "Abstract") Then
            
                    'Dim answers as new ArrayList()
                    answers = questionnaireAnswer.GetAnswers("Objective")
                    If (answers.Count > 0) Then
                        Dim objective as FormsManagement.Answer = answers(0)
                        
                        'Get the text of the questionnaire
                        Dim questItem As FormsManagement.QuestionnaireItem
                        For Each questItem In qV.Items
                            if ( questItem.Name = "Objective") then
                                rexParams.Objective = questItem.HtmlStrippedText
                                rexParams.Objective += vbCrLf 
                                exit for
                            end if
                        Next
                        rexParams.Objective += objective.Value
                    End If
                
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("Significance")
                    If (answers.Count > 0) Then
                        Dim significance as FormsManagement.Answer = answers(0)
                        
                        'Get the text of the questionnaire
                        Dim questItem As FormsManagement.QuestionnaireItem
                        For Each questItem In qV.Items
                            if ( questItem.Name = "Significance") then
                                rexParams.Significance = questItem.HtmlStrippedText
                                rexParams.Significance += vbCrLf
                                exit for
                            end if
                        Next
                        
                        rexParams.Significance += significance.Value
                    End If
                
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("SimExp")
                    if (answers.Count > 0 ) Then
                        Dim simExp as FormsManagement.Answer = answers(0)
                        
                        'Get the text of the questionnaire
                        Dim questItem As FormsManagement.QuestionnaireItem
                        For Each questItem In qV.Items
                            if ( questItem.Name = "SimExp") then
                                rexParams.SimExp = questItem.HtmlStrippedText
                                rexParams.SimExp += vbCrLf
                                
                                exit for
                            end if
                        Next
                        rexParams.SimExp += simExp.Value
                    End If
                
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("Prior")
                    if ( answers.Count > 0 ) Then
                        Dim prior as FormsManagement.Answer = answers(0)
                        
                        'Get the text of the questionnaire
                        Dim questItem As FormsManagement.QuestionnaireItem
                        For Each questItem In qV.Items
                            if ( questItem.Name = "Prior") then
                                rexParams.Prior = questItem.HtmlStrippedText
                                rexParams.Prior += vbCrLf
                                exit for
                            end if
                        Next    			        
                        rexParams.Prior += prior.Value
                    End If
                
                    answers = nothing
                    answers = questionnaireAnswer.GetAnswers("Endpoints")
                    if ( answers.Count > 0 ) Then
                        Dim endpoints as FormsManagement.Answer = answers(0)
                        
                        'Get the text of the questionnaire
                        Dim questItem As FormsManagement.QuestionnaireItem
                        For Each questItem In qV.Items
                            if ( questItem.Name = "Endpoints") then
                                rexParams.Endpoints = questItem.HtmlStrippedText
                                rexParams.Endpoints += vbCrLf
                                exit for
                            end if
                        Next    			        
                        rexParams.Endpoints += endpoints.Value
                End IF
            End If
        Next
    end sub	

    sub AddArrayListItem( byval qa as FormsManagement.QuestionnaireAnswer, byval answerName as string, byval answerValue as string, byref list as ArrayList, byval itemToAdd as string )
        Dim answers as ArrayList = qa.GetAnswers(answerName)
        if ( answers.Count > 0 ) then
            if ( answers(0).Value = answerValue ) then
                list.Add( itemToAdd )
            end if
        end if
    end sub
    
    sub AddHousing( answers as ArrayList, questionnaireName as string, questionnaireAnswer As FormsManagement.QuestionnaireAnswer)
        if not answers is nothing then
        If (answers.Count > 0) Then
				        Dim housingAnswer As FormsManagement.Answer
					    For Each housingAnswer In answers
						    if  housingAnswer.Value = "114CNY1"  Then
						        rexParams.HousingLocation.Add ( "114" )	
						    else if  housingAnswer.Value = "149CNY8"  Then
						        rexParams.HousingLocation.Add ( "149-8" )	
						    else if  housingAnswer.Value = "149CNY9"  Then
						        rexParams.HousingLocation.Add ( "149-9" )	
						    else if  housingAnswer.Value = "65LANDS"  Then
						        rexParams.HousingLocation.Add ( "(Other)" )    						    
                                ' also add in the other description.
                            	rexParams.HousingLocationOther = "65 Landsdowne"
						    else if  housingAnswer.Value = "COX7"  Then
						        rexParams.HousingLocation.Add ( "COX-7" )	
						    else if  housingAnswer.Value = "EDWARDS6"  Then
						        rexParams.HousingLocation.Add ( "EDR-6" )	
						    else if  housingAnswer.Value = "SHRINERS"  Then
						        rexParams.HousingLocation.Add ( "SBI" )	
						    else if  housingAnswer.Value = "SIMCHES8"  Then
						        rexParams.HousingLocation.Add ( "CPZ-8" )
						    else if  housingAnswer.Value = "THIER8"  Then
						        rexParams.HousingLocation.Add ( "Thier-8" )	
						    else if  housingAnswer.Value = "THIERB1"  Then
						        rexParams.HousingLocation.Add ( "Thier-B" )
						    else if  housingAnswer.Value = "WHITE5"  Then
						        rexParams.HousingLocation.Add ( "WHT-5" )
						    else if  housingAnswer.Value = "75CNY"  Then
						        rexParams.HousingLocation.Add ( "75" )
						    else if  housingAnswer.Value = "114CNY1"  Then
						        rexParams.HousingLocation.Add ( "114" )
						    else if  housingAnswer.Value = "OTHERHSE"  Then
						        rexParams.HousingLocation.Add ( "(Other)" )    						    
                                ' also add in the other description, only when this is a call from a std.application questionnaire
                                 if questionnaireName = "STD_APP" then
                                     Dim housingOtherAnswers as new ArrayList()
				                     housingOtherAnswers = questionnaireAnswer.GetAnswers("OtherHousing")   
                                     If (answers.Count > 0) Then
				                         Dim housingOtherAnswer As FormsManagement.Answer = housingOtherAnswers(0)
				                         rexParams.HousingLocationOther = housingOtherAnswer.Value
				                    End If
				                End if
						    end if
					    Next
				    End If
				end if    
    end sub
end module